package com.bxl;

import com.bxl.pojo.News;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SelectNewsImpl extends BaseDao implements SelectNews{


    //根据 id查询 news
    @Override
    public List<News> selectNewa(int id) {
        List<News> list = new ArrayList<News>();
        try {

            String sql="SELECT * FROM `news_category` WHERE id=?";
            Object[] obj = {id};
            ResultSet resultSet= this.selectObj(sql,obj);
            while (resultSet.next()){
                News news = new News();
                news.setId(resultSet.getInt("id"));
                news.setTitle(resultSet.getString("name"));
                list.add(news);

            }
        }catch (Exception e){
            e.printStackTrace();
        }
                return  list;
    }

    @Override
    public List<News> selectNewa(String name) {
        List<News> list = new ArrayList<News>();
        try {
            String sql="SELECT * FROM `news_category` WHERE name=?";
            Object[] obj = {name};
            ResultSet resultSet= this.selectObj(sql,obj);
            while (resultSet.next()){
                News news = new News();
                news.setId(resultSet.getInt("id"));
                news.setTitle(resultSet.getString("name"));
                list.add(news);

            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return list;
    }


    @Override
    public int insertNews(int id, String title) {


        return 0;
    }
}
